package com.qf.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qf.annotation.ProccessInfo;
import com.qf.commons.TableData;
import com.qf.entity.Notify;
import com.qf.mapper.NotifyDao;
import com.qf.service.NotifyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class NotifyServiceImpl implements NotifyService {
    @Resource
    private NotifyDao notifyDao;
    @Override
    public Map<String, Object> getTableNotify(Integer uid, Integer offset, Integer limit) {
        //order=asc&offset=0&limit=10&_=1593690464818
        Page<Notify> page = PageHelper.offsetPage(offset,limit);
        List<Notify> notifies = notifyDao.getNotify(uid);
        System.out.println(notifies.toString());
        long total = page.getTotal();
        Map<String,Object> tableData = new HashMap<>();
        tableData.put("rows",notifies);
        tableData.put("total",total);
        return tableData;
    }

    @Override
    public void changeNotifyStatus(Integer uid, Integer nid) {
        notifyDao.changeNotifyStatus(uid,nid);
    }

    @Override
    @ProccessInfo(value = "新增通知", requireParamInfo = true)
    public void insertNotify(Integer uid, String title, String path) {
        notifyDao.insertNotify(uid, title, path, new Date(), new Date());
    }

    @Override
    public List<Notify> getUnreadNotify(Integer uid) {
        return notifyDao.getUnreadNotify(uid);
    }

    @Override
    public Integer getUnreadNotifyCount(Integer uid) {
        return notifyDao.getUnreadNotifyCount(uid);
    }

    @Override
    public void changeNotifyContent(Integer uid, String title, String path,Integer nid) {
        notifyDao.changeNotifyContent(uid, title, path, new Date(),nid);
        notifyDao.changeReadNotify(nid);
    }
}
